package hibari.server.operations;

import hibari.client.model.Week;
import hibari.server.lib.AdminLog;
import hibari.server.lib.MultiPartRequest;

import javax.servlet.http.HttpServletResponse;

public class RestoreWeek extends PMOperation {

    public RestoreWeek(MultiPartRequest request, HttpServletResponse response) {
        super(request, response);
    }

    @Override
    public void doOperation() {
        try {
            Week week = getPM().getObjectById(Week.class, Long.parseLong(getRequest().getParameter("id")));
            week.setAlive(true);
            getPM().makePersistent(week);
            getPM().close();

            AdminLog.get(getRequest()).addInfo(
                    "<a href=\"/Admin/EditWeek.jsp?id=" + week.getKey() + "\">Week #" + week.getWeekNumber() + "</a> has been restored.");

        } catch (Exception e) {
            AdminLog.get(getRequest()).addError(e.getMessage());
        }
    }

}
